import { checkLogin, getCarShopByAccount } from "../apis/login"
import { setUserInfo } from "./cookieMgr";

export const isLogin=async()=>{
    try{
        const res=await checkLogin();
        const res2=await getCarShopByAccount();
        if(res.code>=0&&res2.code>=0){
            var userInfo={...res.data,...res2.data,carShopId:res2.data.id,accountCreateTime:res.createAtStr,accountUpdateTime:res.updateAtStr,carShopCreateTime:res2.createAtStr,carShopUpdateTime:res2.updateAtStr};
            delete userInfo.createAt;
            delete userInfo.createAtStr;
            delete userInfo.updateAt;
            delete userInfo.updateAtStr;
            setUserInfo(userInfo)
            return true;
        }else{
            uni.navigateTo({
                url:"/pages/login/login"
            })
            return false;
        }
    }catch{
        console.log("error");
        uni.navigateTo({
            url:"/pages/login/login"
        })
        return false;
    }
    
}